<template>
  <div id="acceptaddress">
    <h1 class="titleTag">收货地址</h1>
    <el-form :model="form" :inline="true" class="formone">
      <el-form-item>
        <el-input v-model="form.search" placeholder="客户名称/收货地址/详细地址" size="small"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="small">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button size="small" @click="form.search = ''">清空</el-button>
      </el-form-item>
      <el-form-item>
        <el-button size="small" @click="addTo">新增</el-button>
      </el-form-item>
    </el-form>
    <div class="tableDetail">
      <el-table ref="multipleTable" :data="tableData" height="520" style="width: 100%;">
        <el-table-column align="center" label="地址编码" prop="send_phone"></el-table-column>
        <el-table-column align="center" label="客户名称" prop="send_name"></el-table-column>
        <el-table-column align="center" label="地址类型" prop="send_phone"></el-table-column>
        <el-table-column label="地址">
          <template slot-scope="data">
            <div class="fb"><span>省份</span><span>{{ data.row.send_province }}</span></div>
            <div class="fb"><span>城市</span><span>{{ data.row.send_city }}</span></div>
            <div class="fb"><span>区/县</span><span>{{ data.row.send_area }}</span></div>
          </template>
        </el-table-column>
        <el-table-column label="详细地址" prop="send_address"></el-table-column>
        <el-table-column label="收货人" min-width="140">
          <template slot-scope="data">
            <div class="fb"><span>收货人姓名</span><span>{{ data.row.send_name }}</span></div>
            <div class="fb"><span>收货人电话</span><span>{{ data.row.send_phone }}</span></div>
            <div class="fb"><span>收货人座机</span><span>{{ data.row.send_phone }}</span></div>
          </template>
        </el-table-column>
        <el-table-column label="创建" min-width="140">
          <template slot-scope="data">
            <div class="fb"><span>创建人</span><span>{{ data.row.send_name }}</span></div>
            <div class="fb"><span>创建时间</span><span>{{ data.row.send_phone }}</span></div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="review">编辑</el-button>
            <el-button @click="deleteSure(scope.$index, tableData)" type="text" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 新增地址 -->
    <div class="addAddress">
      <el-dialog title="新增收货地址" :visible.sync="addAddressDialog" center>
        <el-form label-position="left" :model="sendMes" :rules="rules" label-width="90px" ref='ruleForm'>
          <el-row :gutter="40">
            <el-col :span="8">
              <el-form-item label="客户名称" prop="addName">
                <el-input v-model="sendMes.addName" size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="地址名称" prop="addressName">
                <el-input v-model="sendMes.addressName" size="small"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <!-- <el-form-item label="收货地址" prop='addressProvince'> -->
              <city @getProvince="getProvince" @getCity="getCity" @getArea="getArea" title="收货地址"/>
               <!-- </el-form-item> -->
            </el-col>
            <el-col :span="24">
              <el-form-item label="详细地址" prop="addAddress">
                <el-input v-model="sendMes.addAddress" size="small"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="40">
            <el-col :span="8">
              <el-form-item label="收货人" prop="name">
                <el-input v-model="sendMes.name" size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="收货人电话" prop="phone"  label-width="110px">
                <el-input v-model="sendMes.phone" size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="收货人座机" prop="tel"  label-width="110px">
                <el-input v-model="sendMes.tel" size="small"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="submitBUTTON">
          <div><button @click="preserve">保存</button> <button @click="addAddressDialog=false">取消</button> </div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import city from "@/components/city";
export default {
  name: "acceptaddress",
  components: {
    city
  },
  data() {
    // const checkProvince=(rule,value,callback)=>{
    //   console.log(1111111111)
    //   if(this.province&&this.city&&this.area){
    //     callback(new Error('地址不能为空'))
    //   }
    // }
    return {
      addAddressDialog: false,
      searchAddress: "",
      tableData: [
        {
          send_name: "你好",
          send_phone: "18888888888",
          send_province: "山西省",
          send_city: "临汾市",
          send_area: "冀城县",
          send_address: "唐兴镇陵下村鼓楼西33号",
          receive_name: "世界",
          receive_phone: "16666666666",
          receive_province: "贵州省",
          receive_city: "贵阳市",
          receive_area: "云岩区",
          receive_address: "汇金星力城",
          id: "1"
        },
        {
          send_name: "你好0",
          send_phone: "18888888888",
          send_province: "山西省",
          send_city: "临汾市",
          send_area: "冀城县",
          send_address: "唐兴镇陵下村鼓楼西33号",
          receive_name: "世界",
          receive_phone: "16666666666",
          receive_province: "贵州省",
          receive_city: "贵阳市",
          receive_area: "云岩区",
          receive_address: "汇金星力城",
          id: "2"
        }
      ],
      multipleSelection: [],
      radioData: {}, //选中数据
      radioIndex: "", //选中id

      form: {
        //新增地址
        search: ""
      },
      sendMes: {
        //新增地址
        addName: "",
        addAddress: "",
        addressName: "",
        name: "",
        phone: "",
        tel: ""
      },
      rules: {
        addName: [{ required: true, message: "请输入姓名", trigger: "blur" },{pattern: /^[\u2E80-\u9FFF]+$/,  message: "请输入汉字", trigger: "blur"}],
        addressName: [
          { required: true, message: "请输入地址名称", trigger: "blur" }
        ],
        // addressProvince:[{ required: true, message: "请选择地名", trigger: "blur" },{validator:checkProvince,trigger:'blur'}],
        addAddress: [
          { required: true, message: "请输入详细地址", trigger: "blur" }
          
        ],
        phone: [{ required: true, message: "请输入手机号", trigger: "blur" },{pattern:/^(1[3-9])\d{9}$/,message:'手机号格式不符',trigger:'blur'}],
        name: [{ required: true, message: "请输入姓名", trigger: "blur" },{pattern: /^[\u2E80-\u9FFF]+$/,  message: "请输入汉字", trigger: "blur"}],
        tel: [{ required: false, message: "请输入座机号码", trigger: "blur" }]
      }
    };
  },
  created() {},
  mounted() {},
  methods: {
    //新增
    addTo() {
      this.addAddressDialog = true;
    },
    //编辑
    review() {
      this.addAddressDialog = true;
    },
    // 接收省市区数据
    getProvince(val) {
      console.log(val);
      this.province = val;
    },
    getCity(val) {
      console.log(val);
      this.city = val;
    },
    getArea(val) {
      console.log(val);
      this.area = val;
    },
     //保存数据，暂时功能未完善
    preserve(){
      this.$refs.ruleForm.validate((valid)=>{
        if(valid){
          this.addAddressDialog=false;
          console.log('校验成功，发送请求')
        }
      })
    }
  }
};
</script>

<style lang="scss">
.tableDetail {
  .el-radio__label {
    display: none !important;
  }
  .el-radio {
    margin-left: 10px;
  }
}
</style>
<style lang="scss" scoped>
#acceptaddress {
  min-height: 100%;
  background-color: #fff;
  padding: 24px;
  box-sizing: border-box;
  .tableDetail span {
    line-height: 35px;
  }
  .footer {
    text-align: center;
    .btn button {
      cursor: pointer;
      margin: 24px 8px;
      width: 120px;
      line-height: 40px;
      background: $blue;
      border-radius: 10px;
      color: #fff;
      &:nth-of-type(1) {
        background: none;
        color: $blue;
        border: 1px solid $blue;
      }
    }
  }
}
</style>
